function login(){
	$.ajax({
		type:"GET",
		url:"member.php?action=login&r="+Math.random(),
		dataType:"text",
		async:false,
		success:function(e){
			box('登录会员',360,170,e);
			
			$('#join_member').click(function(){
				$('#box_mask').remove();
				$('#box_body').empty();
				$('#box_body').remove();
				register();
			});
			$('#member_forget').click(function(){
				$('#box_mask').remove();
				$('#box_body').empty();
				$('#box_body').remove();
				forget();
			});

			var logins=function(){
				var member_mail=$('#member_mail').val();
				var member_password=$('#member_password').val();
				if ($.trim(member_mail)==''){
					alert('邮件地址不能为空！');
					return false;
				}
				var reg=/([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)/;
				if(!reg.test(member_mail)){
					alert('邮件地址不合法！');
					return false;
				}
				if ($.trim(member_password)==''){
					alert('密码不能为空！');
					return false;
				}
				if (member_password.length<6&&member_password.length>20){
					alert('密码由6-20个字符组成，建议使用英文字母加数字或符号的组合密码。');
					return false;
				}
				$.ajax({
					type:"GET",
					url:"member.php?action=login_ok&member_mail="+encodeURI(member_mail)+"&member_password="+encodeURI(member_password)+"&r="+Math.random(), 
					dataType:"text",
					async:false,
					success:function(e){
						if(e=='error:mail_is_empty'){
							alert('邮件地址不能为空！');
							return false;
						}else if(e=='error:mail_is_error'){
							alert('邮件地址不合法！');
							return false;
						}else if(e=='error:password_is_empty'){
							alert('内容密码不能为空！');
							return false;
						}else if(e=='error:account_is_not_activate'){
							alert('您的账户还没有激活！请到您的邮箱激活帐号！');
							return false;
						}else if(e=='error:account_is_lock'){
							alert('您的账户已被锁定！请联系管理员解锁！');
							return false;
						}else if(e=='error:login_failed'){
							alert('登录失败！');
							return false;
						}
						location.reload();
					}
				});
			};
			/*回车登陆管理*/
			$('#member_password,#member_mail').keydown(function(event){
				var event = event||window.event;
				var keycode = event.keyCode?event.keyCode:event.which?event.which:event.charCode;
				if(keycode==13){
					logins();
				}
			});
			$("#login_submit").click(function(){
				logins();
			});
		}//end request form success
	});//end request form
}
function forget(){
	$.ajax({
		type:"GET",
		url:"member.php?action=forget&r="+Math.random(),
		dataType:"text",
		async:false,
		success:function(e){
			box('找回密码',360,140,e);

			var forget_submit=function(){
				var member_mail=$('#member_mail').val();
				var member_safecode=$('#member_safecode').val();
				if ($.trim(member_mail)==''){
					alert('邮件地址不能为空！');
					return false;
				}
				var reg=/([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)/;
				if(!reg.test(member_mail)){
					alert('邮件地址不合法！');
					return false;
				}
				if ($.trim(member_safecode)==''){
					alert('安全码不能为空！');
					return false;
				}
				$.ajax({
					type:"GET",
					url:"member.php?action=forget_ok&member_mail="+encodeURI(member_mail)+"&member_safecode="+encodeURI(member_safecode)+"&r="+Math.random(), 
					dataType:"text",
					async:false,
					success:function(e){
						alert(e);
						location.reload();
					}
				});
			};
	
			/*回车登陆管理*/
			$('#member_mail,#member_safecode').keydown(function(event){
				var event = event||window.event;
				var keycode = event.keyCode?event.keyCode:event.which?event.which:event.charCode;
				if(keycode==13){
					forget_submit();
				}
			});
			$("#forget_submit_button").click(function(){
				forget_submit();
			});


		}//end request form success
	});//end request form
}
function register(){
	$.ajax({
		type:"GET",
		url:"member.php?action=register&r="+Math.random(),
		dataType:"text",
		async:false,
		success:function(e){
			box('注册会员',380,370,e);
			$("#member_mail").blur(function(){
				$.ajax({
					type:"GET",
					url:"member.php?action=check_member_mail&member_mail="+encodeURI(this.value)+"&r="+Math.random(), dataType:"text",async:false,success:function (e){	
					if (e==1) {
						$("#errMsg_member_mail").html("<img src='/images/no.gif' align='absmiddle'/>");
					}else{
						$("#errMsg_member_mail").html("<img src='/images/yes.gif' align='absmiddle'/>");
					}
				}});
			});

			$("#member_nickname").blur(function(){
				$.ajax({
					type:"GET",
					url:"member.php?action=check_member_nickname&member_nickname="+encodeURI(this.value)+"&r="+Math.random(), dataType:"text",async:false,success:function (e){
					if (e==1) {
						$("#errMsg_member_nickname").html("<img src='/images/no.gif' align='absmiddle'/>");
					}else{
						$("#errMsg_member_nickname").html("<img src='/images/yes.gif' align='absmiddle'/>");
					}
				}}); 
			});
			$("#member_password").blur(function(){
				var Mcolor = "#FFF",Lcolor = "#FFF",Hcolor = "#FFF";
				var m=0,Modes = 0,pwd=this.value;
				for (i=0; i<pwd.length; i++){
					var charType = 0;
					var t = pwd.charCodeAt(i);
					if (t>=48 && t <=57){
					  charType = 1;
					}else if (t>=65 && t <=90){
					  charType = 2;
					}else if (t>=97 && t <=122){
					  charType = 4;
					}else{
					  charType = 4;
					 }
					Modes |= charType;
				}

				for (i=0;i<4;i++){
					if(Modes & 1)m++;
					Modes>>>=1;
				}

				if (pwd.length<=4){
					m = 1;
				}

				switch(m){
				case 1 :
				  Lcolor = "2px solid red";
				  Mcolor = Hcolor = "2px solid #DADADA";
				break;
				case 2 :
				  Mcolor = "2px solid #f90";
				  Lcolor = Hcolor = "2px solid #DADADA";
				break;
				case 3 :
				  Hcolor = "2px solid #3c0";
				  Lcolor = Mcolor = "2px solid #DADADA";
				break;
				case 4 :
				  Hcolor = "2px solid #3c0";
				  Lcolor = Mcolor = "2px solid #DADADA";
				break;
				default :
				  Hcolor = Mcolor = Lcolor = "";
				break;
				}
				if (document.getElementById("pwd_lower")){
					document.getElementById("pwd_lower").style.borderBottom  = Lcolor;
					document.getElementById("pwd_middle").style.borderBottom = Mcolor;
					document.getElementById("pwd_high").style.borderBottom   = Hcolor;
				}
			});
			$("#register_submit").click(function(){
				var member_mail=$('#member_mail').val();
				var member_password=$('#member_password').val();
				var member_password_confirm=$('#member_password_confirm').val();
				var member_safecode=$('#member_safecode').val();
				var member_nickname=$('#member_nickname').val();
				if ($.trim(member_mail)==''){
					alert('邮件地址不能为空！');
					return false;
				}
				var reg=/([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)/;
				if(!reg.test(member_mail)){
					alert('邮件地址不合法！');
					return false;
				}
				if ($.trim(member_password)==''){
					alert('内容密码不能为空！');
					return false;
				}
				if (member_password.length<6&&member_password.length>20){
					alert('密码由6-20个字符组成，建议使用英文字母加数字或符号的组合密码。');
					return false;
				}
				if ($.trim(member_password)!=$.trim(member_password_confirm)){
					alert('二次输入密码不正确！');
					return false;
				}
				if ($.trim(member_nickname)==''){
					alert('昵称不能为空！');
					return false;
				}
				if (member_password.length<2&&member_password.length>10){
					alert('昵称长度不能小于2和大于10!');
					return false;
				}
				if ($.trim(member_safecode)==''){
					alert('安全码不能为空！');
					return false;
				}
				if (member_safecode.length<2&&member_safecode.length>10){
					alert('安全码长度不能小于2和大于10!');
					return false;
				}
				$.ajax({type:"GET", url:"member.php?action=register_ok&member_mail="+encodeURI(member_mail)+"&member_password="+encodeURI(member_password)+"&member_password_confirm="+encodeURI(member_password_confirm)+"&member_nickname="+encodeURI(member_nickname)+"&member_safecode="+encodeURI(member_safecode)+"&r="+Math.random(), dataType:"text",async:false,success:function(e){
					if(e=='error:mail_is_empty'){
						alert('邮件地址不能为空！');
						return false;
					}else if(e=='error:mail_is_error'){
						alert('邮件地址不合法！');
						return false;
					}else if(e=='error:mail_is_occupy'){
						alert('该邮件地址已被占用！');
						return false;
					}else if(e=='error:password_is_empty'){
						alert('内容密码不能为空！');
						return false;
					}else if(e=='error:password_is_error'){
						alert('二次输入密码不正确！');
						return false;
					}else if(e=='error:safecode_is_empty'){
						alert('安全码不能为空！');
						return false;
					}else if(e=='error:nickname_is_empty'){
						alert('昵称不能为空！');
						return false;
					}else if(e=='error:nickname_is_occupy'){
						alert('该昵称已被占用！');
						return false;
					}
					location.reload();
					get_member_info();
				}});
			});

		}//end request form success
	});//end request form
}


function get_member_info(){
	$.ajax({
	type:"GET",
	url:"member.php?action=member_info&r="+Math.random(),
	dataType:"text",
	async:false,
	success:function(e){
		$('#member_info').html(e);
		$('#logout').click(function(){
			$.ajax({type:"GET", url:"member.php?action=logout&r="+Math.random(), dataType:"text",async:false,success:function (){	
				get_member_info();
			}});
		});
	}});	
}
get_member_info();